package com.dingwen.treasure.model.entity.mybatisplus;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dingwen.treasure.model.entity.BaseTree;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 菜单表
 *
 * @author dingwen
 * @TableName sys_menu
 * @date 2022/06/20
 */
@TableName(value = "sys_menu")
@ApiModel(value = "sysMenu", description = "菜单表")
@Accessors(chain = true)
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
public class SysMenu extends BaseEntity implements Serializable, BaseTree {

    @TableField(exist = false)
    private static final long serialVersionUID = -4767157460523806270L;


    /**
     * 主键
     */
    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    public Long id;

    /**
     * 父节点ID
     */
    @ApiModelProperty(value = "父节点ID")
    @TableField(value = "parent_id")
    public Long parenId;


    /**
     * 路由名称
     */
    @ApiModelProperty(value = "路由名称")
    @TableField(value = "name")
    private String name;

    /**
     * 菜单名称
     */
    @ApiModelProperty(value = "菜单名称")
    @TableField(value = "title")
    private String title;


    /**
     * 显示顺序
     */
    @ApiModelProperty(value = "显示顺序")
    @TableField(value = "order_num")
    private Integer orderNum;

    /**
     * 路由地址
     */
    @ApiModelProperty(value = "路由地址")
    @TableField(value = "path")
    private String path;

    /**
     * 组件路径
     */
    @ApiModelProperty(value = "组件路径")
    @TableField(value = "component")
    private String component;

    /**
     * 菜单类型（1: 普通菜单）
     */
    @ApiModelProperty(value = "菜单类型（1: 普通菜单)")
    @TableField(value = "menu_type")
    private Integer menuType;

    /**
     * 菜单状态（1:显示 2:隐藏）
     */
    @ApiModelProperty(value = "菜单状态（1:显示 2:隐藏")
    @TableField(value = "visible")
    private Integer visible;

    /**
     * 权限标识
     */
    @ApiModelProperty(value = "权限标识")
    @TableField(value = "perms")
    private String perms;

    /**
     * 菜单图标
     */
    @ApiModelProperty(value = "菜单图标")
    @TableField(value = "icon")
    private String icon;


    /**
     * 元素集合： 用于构建树结构中间变量
     */
    @TableField(exist = false)
    @JsonIgnore
    private List<SysElement> elements;


    /**
     * 孩子中转集合
     */
    @ApiModelProperty(value = "孩子中转集合")
    @TableField(exist = false)
    private List children;


    /**
     * 设置子项(数据中转)
     *
     * @param children 儿童
     */
    @Override
    public void setChildren(List children) {
        this.children = children;
    }

    /**
     * 获取子项(数据中转)
     *
     * @return {@link List}
     */
    @Override
    public List getChildren() {
        return children;
    }

    /**
     * 获取当前元素ID
     *
     * @return {@link Long}
     */
    @Override
    public Long getId() {
        return id;
    }

    /**
     * 获取树参数id
     *
     * @return {@link Long}
     */
    @Override
    public Long getParenId() {
        return parenId;
    }


    @Builder(toBuilder = true)
    public SysMenu(LocalDateTime createTime, LocalDateTime updateTime, Integer deleted, Integer version, String createBy, String updateBy, String remark, Long id, Long parenId, String name, String title, Integer orderNum, String path, String component, Integer menuType, Integer visible, String perms, String icon, List<SysElement> elements) {
        super(createTime, updateTime, deleted, version, createBy, updateBy, remark);
        this.id = id;
        this.parenId = parenId;
        this.name = name;
        this.title = title;
        this.orderNum = orderNum;
        this.path = path;
        this.component = component;
        this.menuType = menuType;
        this.visible = visible;
        this.perms = perms;
        this.icon = icon;
        this.elements = elements;
    }

}